2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #ifndef __JUCER_PAINTELEMENTRECTANGLE_JUCEHEADER__
27 #define __JUCER_PAINTELEMENTRECTANGLE_JUCEHEADER__
29 #include "jucer_ColouredElement.h"
32 //==============================================================================
35 class PaintElementRectangle
: public ColouredElement
38 //==============================================================================
39 PaintElementRectangle (PaintRoutine
* owner
)
40 : ColouredElement (owner
, "Rectangle", true, false)
44 ~PaintElementRectangle()
48 const Rectangle
<int> getCurrentBounds (const Rectangle
<int>& parentArea
) const
50 return PaintElement::getCurrentBounds (parentArea
); // bypass the ColouredElement implementation
53 void setCurrentBounds (const Rectangle
<int>& newBounds
, const Rectangle
<int>& parentArea
, const bool undoable
)
55 PaintElement::setCurrentBounds (newBounds
, parentArea
, undoable
); // bypass the ColouredElement implementation
58 void draw (Graphics
& g
, const ComponentLayout
* layout
, const Rectangle
<int>& parentArea
)
60 Component parentComponent
;
61 parentComponent
.setBounds (parentArea
);
63 fillType
.setFillType (g
, getDocument(), parentArea
);
65 const Rectangle
<int> r (position
.getRectangle (parentArea
, layout
));
70 strokeType
.fill
.setFillType (g
, getDocument(), parentArea
);
72 g
.drawRect (r
.getX(), r
.getY(), r
.getWidth(), r
.getHeight(),
73 roundToInt (getStrokeType().stroke
.getStrokeThickness()));
77 void getEditableProperties (Array
<PropertyComponent
*>& properties
)
79 ColouredElement::getEditableProperties (properties
);
81 properties
.add (new ShapeToPathProperty (this));
84 void fillInGeneratedCode (GeneratedCode
& code
, String
& paintMethodCode
)
86 if (! fillType
.isInvisible())
89 positionToCode (position
, code
.document
->getComponentLayout(), x
, y
, w
, h
);
91 fillType
.fillInGeneratedCode (code
, paintMethodCode
);
92 s
<< "g.fillRect (" << x
<< ", " << y
<< ", " << w
<< ", " << h
<< ");\n\n";
97 if (isStrokePresent
&& ! strokeType
.isInvisible())
100 positionToCode (position
, code
.document
->getComponentLayout(), x
, y
, w
, h
);
102 strokeType
.fill
.fillInGeneratedCode (code
, paintMethodCode
);
103 s
<< "g.drawRect (" << x
<< ", " << y
<< ", " << w
<< ", " << h
<< ", "
104 << roundToInt (strokeType
.stroke
.getStrokeThickness()) << ");\n\n";
106 paintMethodCode
+= s
;
110 static const char* getTagName() throw() { return "RECT"; }
112 XmlElement
* createXml() const
114 XmlElement
* e
= new XmlElement (getTagName());
115 position
.applyToXml (*e
);
117 addColourAttributes (e
);
122 bool loadFromXml (const XmlElement
& xml
)
124 if (xml
.hasTagName (getTagName()))
126 position
.restoreFromXml (xml
, position
);
127 loadColourAttributes (xml
);
140 const Rectangle
<int> r (getCurrentAbsoluteBounds());
143 path
.addRectangle ((float) r
.getX(), (float) r
.getY(), (float) r
.getWidth(), (float) r
.getHeight());
145 convertToNewPathElement (path
);
149 class ShapeToPathProperty
: public ButtonPropertyComponent
152 ShapeToPathProperty (PaintElementRectangle
* const element_
)
153 : ButtonPropertyComponent ("path", false),
160 element
->convertToPath();
163 const String
getButtonText() const
165 return "convert to a path";
169 PaintElementRectangle
* const element
;
174 #endif // __JUCER_PAINTELEMENTRECTANGLE_JUCEHEADER__